package tech.aistar.corejava.day05.homework01;

/**
 * @author success
 * @version 1.0
 * @description:本类用来演示:
 * @date 2019/7/23 0023
 */
public class Account {
    //定义属性 - 全部使用private
    private int accNo;
    private String accName;
    //当数字不具备计算的特性,只是用来展示的,建议使用String
    private String accPassword;
    private String accTelno;
    private double accBlance;
    private int accType;

    public Account(){

    }

    public Account(int accNo, String accName, String accPassword, String accTelno, double accBlance, int accType) {
        this.accNo = accNo;
        this.accName = accName;
        this.accPassword = accPassword;
        this.accTelno = accTelno;
        this.accBlance = accBlance;
        this.accType = accType;
    }

    public int getAccNo() {
        return accNo;
    }

    public void setAccNo(int accNo) {
        this.accNo = accNo;
    }

    public String getAccName() {
        return accName;
    }

    public void setAccName(String accName) {
        this.accName = accName;
    }

    public String getAccPassword() {
        return accPassword;
    }

    public void setAccPassword(String accPassword) {
        this.accPassword = accPassword;
    }

    public String getAccTelno() {
        return accTelno;
    }

    public void setAccTelno(String accTelno) {
        this.accTelno = accTelno;
    }

    public double getAccBlance() {
        return accBlance;
    }

    public void setAccBlance(double accBlance) {
        this.accBlance = accBlance;
    }

    public int getAccType() {
        return accType;
    }

    public void setAccType(int accType) {
        this.accType = accType;
    }

    @Override
    public String toString() {
        final StringBuilder sb = new StringBuilder("Account{");
        sb.append("accNo=").append(accNo);
        sb.append(", accName='").append(accName).append('\'');
        sb.append(", accPassword='").append(accPassword).append('\'');
        sb.append(", accTelno='").append(accTelno).append('\'');
        sb.append(", accBlance=").append(accBlance);
        sb.append(", accType=").append(accType);
        sb.append('}');
        return sb.toString();
    }

    //业务类和实体类合二为一的方式
    //业务方法仍然是在实体类中
    public void depoist(double money){
        if(money<=0){
            System.out.println("sorry,必须要存入有效金额!");
            return;
        }
        this.accBlance+=money;
    }

    public void withdraw(double money){
        if(money<=0 || money>this.accBlance){
            System.out.println("sorry,余额不足!");
            return;
        }
        this.accBlance-=money;
    }
}
